import { Button, Modal, Form, Input, Radio } from 'antd';
import AddressNew from '@/components/AddressNew';
import {connect} from 'dva';
const FormItem = Form.Item;

@connect(({cooperativeStore})=>({
  list: cooperativeStore.list,
}))
class CollectionCreateForm extends React.Component {
  state={
    cooper:{},
    msgg:'',
    updataMsgg:[]
  }
  componentDidMount(){
  }
   // 很奇怪这里的result就是子组件那bind的第一个参数this，msg是第二个参数
 getChildrenMsg = (result, msg) => {
  // console.log("父组件接收的值111CollectionCreateForm：",msg)
  this.setState({
    msgg: msg
  })
}
changeHandlerUpdata=(result,updataMsg)=>{
  // console.log("updataMsg",updataMsg)
  this.setState({
    updataMsgg: msg
  })
}
  handleSubmit = () => {
    let userInfo = this.props.form.getFieldsValue();
    userInfo["userId"]=1
    // console.log("1111",userInfo)
    this.props.form.validateFields((err,values)=>{
      
      if(!err){
        const { dispatch } = this.props;
        dispatch({
          type:'cooperativeStore/spsWareHouseUpdate',
          payload:{
            data:{

              "airportAddress": values.airportAddress,
              "detailedAddress":values.detailedAddress,
              "contactName": values.contactName,
              "contactNumber": values.contactNumber,
              "goodsType": values.goodsType,
              "id": this.props.val.id,
              "name": values.name,
              "platform": 5,
              "userId": 1,
              "warehouseAddress": this.state.msgg,
              "creator":''
            }
          }
        })
        this.setState({ visible: false });
        // history.go(0)
      }
    })  
    
 };
  render() {

    const { visible, onCancel, onCreate, form, val } = this.props;
    // console.log("val",val)
    const {msgg}=this.state;

        const { getFieldDecorator } = form;
        const formItemLayout ={
          labelCol:{
            xs:24,
            sm:8
          },
          wrapperCol:{
            xs:24,
            sm:12
          }
        }
    return (
      <Modal
            visible={visible}
            title="编辑仓库"
            okText="保存"
            onCancel={onCancel}
            onOk={this.handleSubmit}
          >
            {/* <p>{this.props.txt.name}</p> */}
            <Form layout={"horizontal"} onSubmit={this.handleSubmit}>
              <FormItem label="仓库名称" {...formItemLayout}>
                {
                  getFieldDecorator('name', {
                    initialValue:val.name,
                    rules: [{ required: true, message: '请填写仓库名称!' }],
                })(<Input />)}
              </FormItem>
              <FormItem label="仓库地址"{...formItemLayout}>
                {
                  getFieldDecorator('warehouseAddress', {
                    initialValue:msgg ,// val.warehouseAddress
                    rules: [{ required: true, message: '请填写仓库地址!' }],
                })(<AddressNew parent={ this } parentUpdata={this.changeHandlerUpdata.bind(this)}/>)}
                <h3>{ this.state.childrenMsg }</h3>
                <h3>{ this.state.updataChildrenMsg }</h3>

              </FormItem>


              <FormItem label="详细地址"{...formItemLayout}>
                {
                  getFieldDecorator('detailedAddress', {
                    initialValue:val.detailedAddress,
                    rules: [{ required: true, message: '请填写详细地址!' }],
                })(<Input />)}
              </FormItem>
              <FormItem label="对应机场"{...formItemLayout}>
                {getFieldDecorator('airportAddress', {
                  initialValue:val.airportAddress,
                    rules: [{ required: true, message: '请填写对应机场!' }],
                })(<Input />)}
              </FormItem>
              <FormItem label="货物类型"{...formItemLayout}>
                {
                  getFieldDecorator('goodsType', {
                    initialValue:val.goodsType,
                    rules: [{ required: true, message: '请填写货物类型!' }],
                })(
                  <Input />
                )}
              </FormItem>
              <button type="primary" 
              style={{position: "absolute",right: "50px",bottom:"236px"}}>
                添加
              </button>
              <FormItem label="业务联系人"{...formItemLayout}>
                {getFieldDecorator('contactName', {
                  initialValue:val.contactName,
                    rules: [{ required: true, message: '请填写联系人!' }],
                })(<Input />)}
              </FormItem>
              <FormItem label="联系电话"{...formItemLayout}>
                {getFieldDecorator('contactNumber', {
                  initialValue:val.contactNumber,
                    rules: [{ required: true, message: '请填写联系电话!' }],
                })(<Input />)}
              </FormItem>
            </Form>
          </Modal>
    );
  }
}
export default Form.create()(CollectionCreateForm);
  